package sch.frog.behavioral.interpreter.calculator.expression.end;

import sch.frog.behavioral.interpreter.calculator.expression.Expression;

public class NumberExpression extends EndExpression {

    StringBuilder sb = new StringBuilder();

    public NumberExpression() {
    }

    public NumberExpression(String value) {
        this.sb = sb.append(value);
    }

    public void assemble(char ch){
        sb.append(ch);
    }

    @Override
    public double interpret() {
        return Double.parseDouble(sb.toString());
    }

    @Override
    public int getPriority(){
        return super.getPriority() + 1;
    }

    @Override
    public String toString(){
        return sb.toString();
    }

    @Override
    public Expression assembleTree(Expression expression){
        if(expression.isLeaf()){
            // 两个叶子不能组装到一起
            return null;
        }else{
            return expression.assembleTree(this);
        }
    }

}
